<template>
  <pro-table
    ref="tableRef"
    :columns="columns"
    :fetch="fetch"
    :toolbar="toolbar"
    :operate="operate"
  ></pro-table>
  <AttendanceDia
    :isDisabled="isDisabled"
    :visible="isVisible"
    @close="closeDia"
    :editData="editData"
  ></AttendanceDia>
</template>

<script setup>
import { ref } from "vue";
import AttendanceDia from "./components/AttendanceDia.vue";
import { kqglList } from "@/api/module/constructAndImplement";
import global from "../../global/global.vue";
import moment from "moment";
import { ExclamationCircleOutlined } from "@ant-design/icons-vue";
import { createVNode } from "vue";
import { Modal, message } from "ant-design-vue";

// 项目id
const projectId = global.xmid;

const tableRef = ref();
const isVisible = ref(false);

const closeDia = function () {
  editData.value = [];
  isVisible.value = false;
  tableRef.value.reload();
};

// 表单规则
const columns = ref([
  {
    title: "序号",
    align: "center",
    customRender: ({ text, record, index }) => index + 1,
    width: 60,
  },
  { dataIndex: "time", title: "时间", align: "center" },
  {
    dataIndex: "sgdwkqFileName",
    title: "施工单位考勤文件",
    align: "center",
    document: "sgdwkqFileName",
    domainName: "/api/project/constructionImplementation/kqglDownload",
    documentId: "sgdwkqFile",
  },
  {
    dataIndex: "jldwkqFileName",
    title: "监理单位考勤文件",
    align: "center",
    document: "jldwkqFileName",
    domainName: "/api/project/constructionImplementation/kqglDownload",
    documentId: "jldwkqFile",
  },
]);

// 表单数据
const isDisabled = ref(false);
const fetch = async () => {
  const res = await kqglList({
    id: projectId,
  });
  if (res.data.sign) {
    isDisabled.value = res.data.sign === "2";
  }
  return {
    data: res.data.tabKqglVoList,
  };
};

const editData = ref([]);
/// 工具栏
const toolbar = [
  {
    label: "新增",
    event: function () {
      editData.value = [];
      editData.value.time = moment(new Date()).format("YYYY-MM-DD");
      isVisible.value = true;
    },
  },
];

/// 行操作
const operate = [
  {
    label: "编辑",
    event: function (record) {
      editData.value = record;
      isVisible.value = true;
    },
  },
  {
    label: "删除",
    event: function (record) {
      console.log(record.id);
      // 展示确认弹窗
      Modal.confirm({
        title: () => "温馨提示",
        icon: () => createVNode(ExclamationCircleOutlined),
        content: () => "确认删除吗？",
        onOk() {
          // 调用删除接口
          // 重新获取数据
          tableRef.value.reload();
          message.success("删除成功");
        },
        onCancel() {},
      });
    },
  },
];
</script>

<style lang="scss" scoped></style>
